//
//  CmtShenQuViewController.m
//  Products_B
//
//  Created by lanou on 16/5/31.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "CmtShenQuViewController.h"
#import "RequestManager.h"
#import <UIImageView+WebCache.h>

#import "CmtSecMoreLikeViewController.h"
#import "CmtProductDetailViewController.h"
#import "CmtSecSQTableViewCell.h"
#import "CmtSecFensTableViewCell.h"
#import "CmtAttenCellTableViewCell.h"//社区中关注Cell
#import "CmtRecommendModel.h"//大Model
#import "CmtRecommendComment.h"//评论
#import "CmtRecommendLike.h"//喜欢,fens
#import "CmtRecommendTopics.h"//top
#import "CmtSecAttenLike.h"//fuanzhu
#define kUrlString @"http://api.izhangchu.com/"
#define PKCOLOR(R, G, B) [UIColor colorWithRed:(R) / 255.0 green:(G) / 255.0 blue:(B) / 255.0 alpha:1]
#define PKCOLOR_2(R, G, B, A) [UIColor colorWithRed:(R) / 255.0 green:(G) / 255.0 blue:(B) / 255.0 alpha:A]
@interface CmtShenQuViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong) UIImageView *headView;

@property(nonatomic,strong)UILabel *headLabel;

@property(nonatomic,strong)UILabel *nickLabel;

@property(nonatomic,strong) UIImageView *head_img;

@property(nonatomic,assign)CGPoint contentOffset ;
@property(nonatomic,assign)CGPoint oldContentOffset;
@property(nonatomic,assign)CGPoint newConTentOffset;

@property(nonatomic,strong) UIView *v;


@property(nonatomic,strong)UIScrollView *mainScrollew;
@property(nonatomic,strong)UITableView *leftTableView;
@property(nonatomic,strong)UITableView *centerTableView;
@property(nonatomic,strong)UITableView *rightTableView;

@property(nonatomic,assign)NSInteger count1;
@property(nonatomic,assign)NSInteger count2;
@property(nonatomic,assign)NSInteger count3;

@property(nonatomic,strong)UIView *lineV;

@property(nonatomic,strong)NSString *background;
@property(nonatomic,strong)NSString *declaration;
@property(nonatomic,strong)NSString *headphoto;
@property(nonatomic,strong)NSString *nickname;
@property(nonatomic,strong)NSNumber *tongji_be_follow;
@property(nonatomic,strong)NSNumber *tongji_follow;
@property(nonatomic,strong)NSNumber *tongji_post;

@property(nonatomic,strong)NSMutableArray *modelArray;
@property(nonatomic,strong)NSMutableArray *likeArray;
@property(nonatomic,strong)NSMutableArray *attenArray;

@property(nonatomic,assign)NSInteger page;
@end

@implementation CmtShenQuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    导航栏
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBarHidden = YES;
   
    self.navigationController.view.backgroundColor = [UIColor whiteColor];
    UIBarButtonItem *lfBarButton = [[UIBarButtonItem alloc] initWithTitle:@"<—" style:(UIBarButtonItemStylePlain) target:self action:@selector(backAction:)];
    lfBarButton.tintColor = [UIColor grayColor];
    self.navigationItem.leftBarButtonItem = lfBarButton;
    
//  假导航栏
    self.v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth,64 )];
    [self.navigationController.view addSubview:_v];
    _v.backgroundColor = [UIColor clearColor];

    UIButton *backBtn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    backBtn.frame = CGRectMake(0, 20, 50, 30);
    [backBtn setTitle:@"<—" forState:(UIControlStateNormal)];
    backBtn.tintColor = [UIColor whiteColor];
    [backBtn addTarget:self action:@selector(backAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [_v addSubview:backBtn];
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight) style:(UITableViewStylePlain)];
    [self.view addSubview:_tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
//    表头
    self.headView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 220)];
    _headView.backgroundColor = [UIColor clearColor];
    _headView.image = [UIImage imageNamed:@"qqq.png"];
    self.tableView.tableHeaderView = _headView;
    
//    头像
    self.head_img = [[UIImageView alloc]initWithFrame:CGRectMake(30, 220 - 125, 50, 50)];
    self.head_img.backgroundColor = [UIColor redColor];
    self.head_img.layer.cornerRadius = 25;
    self.head_img.layer.masksToBounds = YES;
    [self.headView addSubview:self.head_img];
    
//    
    UIView *headLv = [[UIView alloc]initWithFrame:CGRectMake(0, 220 - 100, kWidth, 100)];
    headLv.backgroundColor = PKCOLOR(20, 20, 20);
    headLv.alpha = 0.2;
    [self.headView addSubview:headLv];
    
    self.nickLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 127, 120, 25)];
    self.nickLabel.text = @"贱人";
    self.nickLabel.textColor = [UIColor whiteColor];
    self.nickLabel.font = [UIFont systemFontOfSize:15];
    [self.headView addSubview:self.nickLabel];
    
    self.headLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 160, kWidth - 40, 60)];
    self.headLabel.font = [UIFont systemFontOfSize:15];
    self.headLabel.numberOfLines = 0;
    self.headLabel.textColor = [UIColor whiteColor];
    self.headLabel.text = @"飞流直下三千尺，人间下流第一人,asjklcjjdjklfdjfdjlkd";
    [self.headView addSubview:self.headLabel];
    
    [self.tableView registerClass:[CmtSecSQTableViewCell class] forCellReuseIdentifier:@"CmtSecSQCell"];

    self.view.backgroundColor = [UIColor greenColor];
    
    self.page = 1;
    
    [self requestDataWithUseid:self.user_id];
    [self reqestDataWith];
    [self requestDataWithFens];
    [self requestDataWithAttention];
    self.modelArray = [[NSMutableArray alloc] initWithCapacity:1];
    self.likeArray = [[NSMutableArray alloc] initWithCapacity:1];
    self.attenArray= [[NSMutableArray alloc]initWithCapacity:10];
    
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        self.page += 1;
        [self reqestDataWith];
        [self requestDataWithFens];
        [self requestDataWithAttention];
    }];
    
    self.tableView.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
        self.page = 1;
        [self.modelArray removeAllObjects];
        [self.likeArray removeAllObjects];
        [self.attenArray removeAllObjects];
        [self reqestDataWith];
        [self requestDataWithFens];
        [self requestDataWithAttention];
    }];
}

//请求关注数据
- (void)requestDataWithAttention{

    NSDictionary *pardic = @{@"user_id_target":self.user_id,@"page":[NSString stringWithFormat:@"%ld",(long)self.page],@"methodName":@"FensiList",@"size":@"20",@"version":@"4.40&"};
    [RequestManager requestWithUrl:kUrlString requestType:(RequestTypePOST) parDic:pardic finish:^(NSData *data) {
        NSDictionary *jsDic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
        
        NSArray *dataArr = jsDic[@"data"][@"data"];
        for (NSDictionary *dic in dataArr) {
            
            CmtSecAttenLike *attenModel = [[CmtSecAttenLike alloc]init];
            [attenModel setValuesForKeysWithDictionary:dic];
            [self.attenArray addObject:attenModel];
        }
        
        [self.rightTableView reloadData];
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    } error:nil];
}

//请求粉丝数据
- (void)requestDataWithFens{

    NSDictionary *pardic = @{@"user_id_target":self.user_id,@"page":[NSString stringWithFormat:@"%ld",(long)self.page],@"methodName":@"GuanzhuList",@"size":@"20",@"version":@"4.40&"};
    [RequestManager requestWithUrl:kUrlString requestType:(RequestTypePOST) parDic:pardic finish:^(NSData *data) {
        NSDictionary *jsdic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
        
        NSArray *dataArr = jsdic[@"data"][@"data"];
        for (NSDictionary *dic in dataArr) {
            
            CmtRecommendLike *fensModel = [[CmtRecommendLike alloc]init];
            [fensModel setValuesForKeysWithDictionary:dic];
            [self.likeArray addObject:fensModel];
        }
        
        [self.centerTableView reloadData];
        
    } error:nil];
}

//请求headView数据
-(void)requestDataWithUseid:(NSString *)usr_id{

    NSDictionary *par = @{@"methodName":@"UserInfo",@"visitor_id":self.user_id,@"version":@"4.40&"};
    [RequestManager requestWithUrl:@"http://api.izhangchu.com/" requestType:(RequestTypePOST) parDic:par finish:^(NSData *data) {
        NSDictionary *jsDic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
//        NSLog(@"%@",jsDic);
        
        self.background = jsDic[@"data"][@"background"];

        self.declaration = jsDic[@"data"][@"declaration"];
        self.headphoto = jsDic[@"data"][@"headphoto"];
        self.tongji_be_follow = jsDic[@"data"][@"tongji_be_follow"];
        self.tongji_follow = jsDic[@"data"][@"tongji_follow"];
        self.tongji_post = jsDic[@"data"][@"tongji_post"];
        self.nickname = jsDic[@"data"][@"nickname"];
        
        if (![self.background isEqualToString:@""]) {
            
            [self.headView sd_setImageWithURL:[NSURL URLWithString:self.background]];
        }
        
        else{
          [self.headView sd_setImageWithURL:[NSURL URLWithString:@"http://img2.imgtn.bdimg.com/it/u=1210813349,2183526045&fm=21&gp=0.jpg"]];
        }
        
        [self.head_img sd_setImageWithURL:[NSURL URLWithString:self.headphoto]];
        self.headLabel.text = self.declaration;
        self.nickLabel.text = self.nickname;
        self.count1 = [self.tongji_post integerValue];
        self.count2 = [self.tongji_follow integerValue];
        self.count3 = [self.tongji_be_follow integerValue];
        
        self.navigationItem.title = [NSString stringWithFormat:@"%@",self.nickname];
//        self.navigationItem.title = @"lalallaal";
        
//        NSLog(@"%ld",(long)self.count1);
        [self.tableView reloadData];
        
    } error:^(NSError *error) {
        
    }];
}
//请求作品的数据
-(void)reqestDataWith{

    NSDictionary *parDic = @{@"visitor_id":self.user_id,@"page":[NSString stringWithFormat:@"%ld",(long)self.page],@"methodName":@"ShequUlist",@"size":@"20",@"version":@"4.40&"};
    
    [RequestManager requestWithUrl:@"http://api.izhangchu.com/" requestType:(RequestTypePOST) parDic:parDic finish:^(NSData *data) {
        
        NSDictionary *jsDic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
        
//        NSLog(@"%@",jsDic);
        
        NSArray *dataArr = jsDic[@"data"][@"data"];
        for (NSDictionary *dic in dataArr) {
            CmtRecommendModel *recModel = [[CmtRecommendModel alloc]init];
//            NSLog(@"likeArr= %@",dic[@"like"]);
            
            NSArray *likeArr = dic[@"like"];
            
            for (NSDictionary *likeDic in likeArr) {
                CmtRecommendLike *likeModel = [[CmtRecommendLike alloc]init];
                [likeModel setValuesForKeysWithDictionary:likeDic];
                
                [recModel.like addObject:likeModel];
                
//                NSLog(@"%ld",recModel.like.count);
            }
            
            [recModel setValuesForKeysWithDictionary:dic];
            
            [_modelArray addObject:recModel];
        }

        [self.leftTableView reloadData];
        
        
    } error:nil];
    


}

//隐藏tabBar
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
        self.navigationController.navigationBarHidden = YES;

    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (self.leftTableView == tableView) {
        
        return self.modelArray.count;
    }
    if (self.centerTableView == tableView) {
        NSLog(@"粉丝%lu",(unsigned long)_attenArray.count);
        return self.likeArray.count;
    }
    if (self.rightTableView == tableView) {
        NSLog(@"关注%lu",(unsigned long)_attenArray.count);
        return self.attenArray.count;
    }
    return 1;
}

//返回Cell的方法；
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    左边的tableView
    if (tableView == self.leftTableView) {
        
        
        CmtAttenCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cmtCell" forIndexPath:indexPath];
        
        CmtRecommendModel *model = self.modelArray[indexPath.row];
        cell.model = model;
        
        cell.head_img.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(CmtAttenCellTap:)];
        
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(CmtAttenCellTap:)];
        
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(CmtAttenCellTap:)];
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(CmtAttenCellTap:)];
        UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(CmtAttenCellTap:)];
        UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(CmtAttenCellTap:)];
        
        [cell.head_img addGestureRecognizer:tap];
        cell.head_img.tag = 10 + indexPath.row;
        
        [cell.image1 addGestureRecognizer:tap1];
        cell.image1.tag = 2000 + indexPath.row;
        [cell.image2 addGestureRecognizer:tap2];
        cell.image2.tag = 3000 + indexPath.row;
        [cell.image3 addGestureRecognizer:tap3];
        cell.image3.tag = 4000 + indexPath.row;
        [cell.image4 addGestureRecognizer:tap4];
        cell.image4.tag = 5000 + indexPath.row;
        [cell.image5 addGestureRecognizer:tap5];
        cell.image5.tag = 6000 + indexPath.row;
        cell.cellblock = ^(NSString *_id){
            
            CmtSecMoreLikeViewController *CmtMLVc = [[CmtSecMoreLikeViewController alloc]init];
            CmtMLVc.post_id = _id;
            [self.navigationController pushViewController:CmtMLVc animated:YES];
            
            [self.navigationController setNavigationBarHidden:NO animated:YES];
            
            [self.v removeFromSuperview];
            self.tableView.frame = CGRectMake(0, -70, kWidth, kHeight);
        };
    
        return cell;
    }
//    用中间的tableView和右边的tableView
    if (tableView == self.centerTableView | tableView == self.rightTableView) {
        CmtSecFensTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CmtFenSCell" forIndexPath:indexPath];
        if (tableView == self.self.centerTableView) {
            CmtRecommendLike *likeModel = self.likeArray[indexPath.row];
            cell.model = likeModel;
        }
        else{
            CmtSecAttenLike *attenModel = self.attenArray[indexPath.row];
            cell.model = attenModel;
        }
        return cell;
    }
    if (tableView == self.tableView) {
        
        CmtSecSQTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CmtSecSQCell" forIndexPath:indexPath];
        [self SetCellScrollew:cell];
        return cell;
    }
    return [[UITableViewCell alloc]init];
}


//点击Cell的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView == _leftTableView) {
        
           CmtRecommendModel *model = self.modelArray[indexPath.row];
        CmtProductDetailViewController *CmtPDVc = [[CmtProductDetailViewController alloc]init];
        CmtPDVc.post_id = model._id;
        [self.navigationController pushViewController:CmtPDVc animated:YES];
    }
}


//手势
-(void)CmtAttenCellTap:(UITapGestureRecognizer *)tap{
    
    NSLog(@"点击了手势");
    CmtShenQuViewController *CmtSQVc = [[CmtShenQuViewController alloc]init];
    NSInteger index = 0;
    NSInteger count = tap.view.tag;
    if ( count > 0 && count < 2000) {
        index = count - 10;
        CmtRecommendModel *model = self.modelArray[index];
        CmtSQVc.user_id = model.user_id;
    }else{
        CmtRecommendModel *model = self.modelArray[index];
        self.likeArray = model.like[index];
        if (count > 2000 && count< 3000) {
            index = 0;
        }
        if (count > 3000 && count < 4000) {
            index = 1;
        }
        if (count > 4000 && count < 5000) {
            index = 2;
        }
        if (count > 5000 && count < 6000) {
            index = 3;
        }if (count > 6000) {
            index = 4;
        }
        NSDictionary *likeModel = (NSDictionary *)model.like[index];
        
        CmtSQVc.user_id = likeModel[@"user_id"];
    }
    
    [self.navigationController pushViewController:CmtSQVc animated:YES];
    
    
}


//Cell中的ScrollView
-(void)SetCellScrollew:(CmtSecSQTableViewCell *)cell{

    self.mainScrollew = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight - 120)];
    self.mainScrollew.contentSize = CGSizeMake(kWidth * 3, kHeight - 120);
    self.mainScrollew.bounces = NO;
    self.mainScrollew.delegate = self;
    self.mainScrollew.pagingEnabled = YES;
    self.leftTableView = [self SetSmallTableView:0];
    self.centerTableView = [self SetSmallTableView:1];
    self.rightTableView = [self SetSmallTableView:2];
    
    [self.leftTableView registerNib:[UINib nibWithNibName:@"CmtAttenCellTableViewCell" bundle:nil] forCellReuseIdentifier:@"cmtCell"];
    [self.centerTableView registerNib:[UINib nibWithNibName:@"CmtSecFensTableViewCell" bundle:nil] forCellReuseIdentifier:@"CmtFenSCell"];
    [self.rightTableView registerNib:[UINib nibWithNibName:@"CmtSecFensTableViewCell" bundle:nil] forCellReuseIdentifier:@"CmtFenSCell"];
    

    
    self.leftTableView.delegate = self;
    self.leftTableView.dataSource = self;
    
    self.centerTableView.delegate = self;
    self.centerTableView.dataSource = self;
    
    self.rightTableView.delegate = self;
    self.rightTableView.dataSource = self;
    [self.mainScrollew addSubview:_leftTableView];
    [self.mainScrollew addSubview:_centerTableView];
    [self.mainScrollew addSubview:_rightTableView];

    [cell.contentView addSubview:_mainScrollew];
}

//创建TableView
-(UITableView *)SetSmallTableView:(NSInteger)index{

    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(kWidth * index, 0, kWidth, kHeight - 120) style:(UITableViewStylePlain)];
    tableView.scrollEnabled = NO;
    tableView.bounces = NO;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.backgroundColor = PKCOLOR(10 + 10 * index, 20 + 10 *index, 30 + 10 * index);
    return tableView;
}
//返回区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (self.tableView == tableView) {
        return 50;
    }
    
    return 0;
}
//返回区头
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (tableView == self.leftTableView) {
        return [[UIView alloc] init];
    }
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 50)];
    view.backgroundColor = [UIColor cyanColor];
    
    UIButton *but1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    UIButton *but2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    UIButton *but3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    but1.frame = CGRectMake(50, 10, (kWidth - 100) / 3, 30);
    but1.titleLabel.font = [UIFont systemFontOfSize:16];
    [but1 setTitle:[NSString stringWithFormat:@"作品（%ld）",self.count1] forState:(UIControlStateNormal)];
    [but1 addTarget:self action:@selector(But1Action) forControlEvents:(UIControlEventTouchUpInside)];
    self.lineV = [[UIView alloc] initWithFrame:CGRectMake(50 + (kWidth - 80) / 3 * 0 , 47, (kWidth - 100) / 3, 3)];

//    self.lineV = [[UIView alloc] initWithFrame:CGRectMake(50 , 45, (kWidth - 100) / 3, 3)];
    self.lineV.backgroundColor = [UIColor orangeColor];
    but2.frame = CGRectMake(50 + (kWidth - 80) / 3, 10, (kWidth - 80) / 3, 30);
    but2.titleLabel.font = [UIFont systemFontOfSize:16];
    [but2 setTitle:[NSString stringWithFormat:@"粉丝（%ld）",self.count2]
        forState:(UIControlStateNormal)];
    [but2 addTarget:self action:@selector(but2Action) forControlEvents:(UIControlEventTouchUpInside)];
    but3.frame = CGRectMake(50 + (kWidth - 80) / 3 * 2, 10, (kWidth - 80) / 3 + 10, 30);
    but3.titleLabel.font = [UIFont systemFontOfSize:16];
    [but3 setTitle:[NSString stringWithFormat:@"关注（%ld）",self.count3] forState:(UIControlStateNormal)];
    [but3 addTarget:self action:@selector(but3Action) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    [view addSubview:but1];
    [view addSubview:but2];
    [view addSubview:but3];
    [view addSubview:self.lineV];
//    NSLog(@"old =  %lf",self.lineV.frame.origin.x);

    return view;
}

-(void)But1Action{
    
  
    self.lineV.frame = CGRectMake(50 + (kWidth - 100) / 3 * 0 , 47, (kWidth - 100) / 3, 3);
//    NSLog(@"old =  %lf",self.lineV.frame.origin.x);
    [self.mainScrollew setContentOffset:CGPointMake(0, 0) animated:YES];
    
}
-(void)but2Action{
    
   self.lineV.frame= CGRectMake(50 + (kWidth - 100) / 3 * 1 , 47, (kWidth - 100) / 3, 3);
//    NSLog(@"old =  %lf",self.lineV.frame.origin.x);
    [self.mainScrollew setContentOffset:CGPointMake(kWidth, 0) animated:YES];
}
-(void)but3Action{
    self.lineV.frame = CGRectMake(50 + (kWidth - 100) / 3 * 2 , 47, (kWidth - 100) / 3, 3);
//    NSLog(@"old =  %lf",self.lineV.frame.origin.x);
    [self.mainScrollew setContentOffset:CGPointMake(kWidth * 2, 0) animated:YES];

}

//返回Cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.leftTableView == tableView) {
        return 430;
    }
    if (self.centerTableView == tableView | self.rightTableView == tableView) {
        return 80;
    }
    return kHeight - 120;
}

//滚动时调用的方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    当前偏移量
    self.newConTentOffset = scrollView.contentOffset;
    if (self.tableView == scrollView) {
/*        CGFloat Y = scrollView.contentOffset.y;
        if ( Y > 64) {
//            
//            self.navigationController.navigationBarHidden = NO;
//            self.v.backgroundColor = [UIColor whiteColor];
//            self.v.hidden = YES;
//        }else{
//            self.navigationController.navigationBarHidden = YES;
//            self.v.backgroundColor = [UIColor clearColor];
//            self.v.hidden = NO;
//        }
 */
/*        if (_newConTentOffset.y > _oldContentOffset.y && _oldContentOffset.y > _contentOffset.y) {
            NSLog(@"向上滚动");
        }
        else if (_newConTentOffset.y < _oldContentOffset.y && _oldContentOffset.y < _contentOffset.y){
            NSLog(@"向下滚动");
        }
        else{
            NSLog(@"dragging");
        }
 */
        if (scrollView.dragging) {
            
//            if ((self.newConTentOffset.y - _contentOffset.y)  > 70 | scrollView.contentOffset.y > 0) {
            
            if (self.newConTentOffset.y >= 70) {

//                隐藏导航栏
                [self.navigationController setNavigationBarHidden:NO animated:YES];
                
                [self.v removeFromSuperview];
                self.tableView.frame = CGRectMake(0, -70, kWidth, kHeight);
                
//                隐藏选项栏
                self.tabBarController.tabBar.hidden = NO;
                
//                self.tableView.scrollEnabled = NO;
                
            }
            else{
                self.navigationController.navigationBarHidden = YES;
                 self.tableView.frame = CGRectMake(0, 0, kWidth, kHeight);
                [self.navigationController.view addSubview:_v];
            }
            
        }
        
    }
    if (scrollView == _mainScrollew) {
        
/*        if (_newConTentOffset.x > _oldContentOffset.x && _oldContentOffset.x > _contentOffset.x) {
//            NSLog(@"向左滚动");
//             NSLog(@"old =  %lf",self.lineV.frame.origin.x);
//            CGFloat scale = _newConTentOffset.x / kWidth;
//            
//            CGRect newFrame = self.lineV.frame;
//            
//            newFrame.origin.x = newFrame.origin.x * (1 - scale);
//            
//            self.lineV.frame = newFrame;
//            NSLog(@"new =  %lf",self.lineV.frame.origin.x);
//        }
//        else if (_newConTentOffset.x < _oldContentOffset.x && _oldContentOffset.x< _contentOffset.x){
//            
//            NSLog(@"向右滚动");
//            
//            NSLog(@"old =  %lf",self.lineV.frame.origin.x);
//            
//            CGFloat scale = _newConTentOffset.x / kWidth;
//            
//            CGRect newFrame = self.lineV.frame;
//            
//            newFrame.origin.x = newFrame.origin.x * (1 - scale);
//            
//            self.lineV.frame = newFrame;
//            NSLog(@"new =  %lf",self.lineV.frame.origin.x);
//        }*/
    }
}

//结束拖拽
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

    self.oldContentOffset = scrollView.contentOffset;
}
//开始拖拽
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{

    self.contentOffset = scrollView.contentOffset;
}


//结束减速
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    if (scrollView == _mainScrollew) {
        
        if (scrollView.contentOffset.x / kWidth == 0) {
            
            self.lineV.frame = CGRectMake(50 + (kWidth - 100) / 3 * 0, 47, (kWidth - 100) / 3, 3);
        }
        if (scrollView.contentOffset.x / kWidth == 1){
            self.lineV.frame = CGRectMake(50 + (kWidth - 100) / 3 * 1, 47, (kWidth - 100) / 3, 3);
        }
        if (scrollView.contentOffset.x / kWidth == 2){
            self.lineV.frame = CGRectMake(50 + (kWidth - 100) / 3 * 2 , 47, (kWidth - 100) / 3 + 20, 3);
        }
        
    }

}

-(void)backAction:(UIButton *)button{
//    CommunityViewController *CmtVc = self.navigationController.viewControllers[0];
    
    NSLog(@"``````````%@",self.navigationController.viewControllers[0]);
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
